﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Model;

namespace BLL
{
    public class GET_DDAL_SFP
    {

        private string 换行的字符 = "\n\t"; // \n\t
        public DDAL_SFP GetDDAL_SFPmodel(string result)
        {
            DDAL_SFP model = new DDAL_SFP();
            string[] arrayList = result.Split(new string[] { 换行的字符 }, StringSplitOptions.None);
            foreach (string s in arrayList)
            {
                if (s.IndexOf("Vendor:") != -1)
                {
                    model.Vendor = s.Substring(s.IndexOf("Vendor:"), s.Length - s.IndexOf("Vendor:"));
                    model.Vendor = model.Vendor.Replace("Vendor:", "").Trim();
                }
                if (s.IndexOf("Serial:") != -1)
                {
                    model.Serial = s.Substring(s.IndexOf("Serial:"), s.Length - s.IndexOf("Serial:"));
                    model.Serial = model.Serial.Replace("Serial:", "").Trim();
                }
                if (s.IndexOf("Bitrate:") != -1)
                {
                    model.Bitrate = s.Substring(s.IndexOf("Bitrate:"), s.Length - s.IndexOf("Bitrate:"));
                    model.Bitrate = model.Bitrate.Replace("Bitrate:", "").Trim();
                }
                if (s.IndexOf("Wavelength:") != -1)
                {
                    model.Wavelength = s.Substring(s.IndexOf("Wavelength:"), s.Length - s.IndexOf("Wavelength:"));
                    model.Wavelength = model.Wavelength.Replace("Wavelength:", "").Trim();
                }
                if (s.IndexOf("Connector:") != -1)
                {
                    model.Connector = s.Substring(s.IndexOf("Connector:"), s.Length - s.IndexOf("Connector:"));
                    model.Connector = model.Connector.Replace("Connector:", "").Trim();
                }
                if (s.IndexOf("Part number:") != -1)
                {
                    model.Part_number = s.Substring(s.IndexOf("Part number:"), s.Length - s.IndexOf("Part number:"));
                    model.Part_number = model.Part_number.Replace("Part number:", "").Trim();
                }

                if (s.IndexOf("Input power =") != -1)
                {
                    model.Input_power = coherency字符的处理(s, "Input power =");
                }
                if (s.IndexOf("Input power in dbm =") != -1)
                {
                    model.Input_power_in_dbm = s.Substring(s.IndexOf("Input power in dbm ="), s.Length - s.IndexOf("Input power in dbm ="));
                    model.Input_power_in_dbm = model.Input_power_in_dbm.Replace("Input power in dbm =", "").Trim();
                }
                if (s.IndexOf("Output power =") != -1)
                {
                    model.Output_power = coherency字符的处理(s, "Output power =");
                }
                if (s.IndexOf("Output power in dbm =") != -1)
                {
                    model.Output_power_in_dbm = s.Substring(s.IndexOf("Output power in dbm ="), s.Length - s.IndexOf("Output power in dbm ="));
                    model.Output_power_in_dbm = model.Output_power_in_dbm.Replace("Output power in dbm =", "").Trim();
                }
                if (s.IndexOf("Voltage =") != -1)
                {
                    model.Voltage = coherency字符的处理(s, "Voltage =");
                    //model.Voltage = s.Substring(s.IndexOf("Voltage:"), s.IndexOf(",") - s.IndexOf("Voltage:"));
                    //model.Voltage = model.Voltage.Replace("Voltage:", "").Trim();
                }
                if (s.IndexOf("Temperature =") != -1)
                {
                    model.Temperature = coherency字符的处理(s, "Temperature =");
                    //model.Temperature = s.Substring(s.IndexOf("Temperature:"), s.IndexOf(",") - s.IndexOf("Temperature:"));
                    //model.Temperature = model.Temperature.Replace("Temperature:", "").Trim();
                }

            }
            return model;

        }
        public DDAL_SFP_DEV_LOCAL_RADIO_IF GetDDAL_SFP_DEV_LOCAL_RADIO_IF_model(string result)
        {
            DDAL_SFP_DEV_LOCAL_RADIO_IF model = new DDAL_SFP_DEV_LOCAL_RADIO_IF();
            string[] arrayList = result.Split(new string[] { 换行的字符 }, StringSplitOptions.None);
            foreach (string s in arrayList)
            {
                if (s.IndexOf("Vendor:") != -1)
                {
                    model.Vendor = s.Substring(s.IndexOf("Vendor:"), s.Length - s.IndexOf("Vendor:"));
                    model.Vendor = model.Vendor.Replace("Vendor:", "").Trim();
                }
                if (s.IndexOf("Serial:") != -1)
                {
                    model.Serial = s.Substring(s.IndexOf("Serial:"), s.Length - s.IndexOf("Serial:"));
                    model.Serial = model.Serial.Replace("Serial:", "").Trim();
                }
                if (s.IndexOf("Bitrate:") != -1)
                {
                    model.Bitrate = s.Substring(s.IndexOf("Bitrate:"), s.Length - s.IndexOf("Bitrate:"));
                    model.Bitrate = model.Bitrate.Replace("Bitrate:", "").Trim();
                }
                if (s.IndexOf("Wavelength:") != -1)
                {
                    model.Wavelength = s.Substring(s.IndexOf("Wavelength:"), s.Length - s.IndexOf("Wavelength:"));
                    model.Wavelength = model.Wavelength.Replace("Wavelength:", "").Trim();
                }
                if (s.IndexOf("Connector:") != -1)
                {
                    model.Connector = s.Substring(s.IndexOf("Connector:"), s.Length - s.IndexOf("Connector:"));
                    model.Connector = model.Connector.Replace("Connector:", "").Trim();
                }
                if (s.IndexOf("Part number:") != -1)
                {
                    model.Part_number = s.Substring(s.IndexOf("Part number:"), s.Length - s.IndexOf("Part number:"));
                    model.Part_number = model.Part_number.Replace("Part number:", "").Trim();
                }

                if (s.IndexOf("Input power =") != -1)
                {
                    model.Input_power = coherency字符的处理(s, "Input power =");
                }
                if (s.IndexOf("Input power in dbm =") != -1)
                {
                    model.Input_power_in_dbm = s.Substring(s.IndexOf("Input power in dbm ="), s.Length - s.IndexOf("Input power in dbm ="));
                    model.Input_power_in_dbm = model.Input_power_in_dbm.Replace("Input power in dbm =", "").Trim();
                }
                if (s.IndexOf("Output power =") != -1)
                {
                    model.Output_power = coherency字符的处理(s, "Output power =");
                }
                if (s.IndexOf("Output power in dbm =") != -1)
                {
                    model.Output_power_in_dbm = s.Substring(s.IndexOf("Output power in dbm ="), s.Length - s.IndexOf("Output power in dbm ="));
                    model.Output_power_in_dbm = model.Output_power_in_dbm.Replace("Output power in dbm =", "").Trim();
                }
                if (s.IndexOf("Voltage =") != -1)
                {
                    model.Voltage = coherency字符的处理(s, "Voltage =");
                    //model.Voltage = s.Substring(s.IndexOf("Voltage:"), s.IndexOf(",") - s.IndexOf("Voltage:"));
                    //model.Voltage = model.Voltage.Replace("Voltage:", "").Trim();
                }
                if (s.IndexOf("Temperature =") != -1)
                {
                    model.Temperature = coherency字符的处理(s, "Temperature =");
                    //model.Temperature = s.Substring(s.IndexOf("Temperature:"), s.IndexOf(",") - s.IndexOf("Temperature:"));
                    //model.Temperature = model.Temperature.Replace("Temperature:", "").Trim();
                }
            }
            return model;

        }
        public List<DDAL_SFP> GetDDAL_SFPmodelList(string result)
        {
            List<DDAL_SFP> DDAL_SFPmodelList = new List<DDAL_SFP>();
            List<string> DDAL_SFP_LIST = new List<string>();

            int i = 0;
            while (result.IndexOf("DDAL_SFP_" + i.ToString()) != -1)
            {
                int indexEnd = result.Length;
                int j = i + 1;
                if (result.IndexOf("DDAL_SFP_" + (j).ToString()) != -1)
                    indexEnd = result.IndexOf("DDAL_SFP_" + (j));
                else
                    indexEnd = result.IndexOf("DDAL_SFP_DEV_LOCAL_RADIO_IF_");

                DDAL_SFP_LIST.Add(result.Substring(result.IndexOf("DDAL_SFP_" + i.ToString()), indexEnd - result.IndexOf("DDAL_SFP_" + i.ToString())));

                i++;
            }
            for (int i1 = 0; i1 < DDAL_SFP_LIST.Count; i1++)
            {
                DDAL_SFP model = GetDDAL_SFPmodel(DDAL_SFP_LIST[i1]);
                DDAL_SFPmodelList.Add(model);
            }
            return DDAL_SFPmodelList;


        }
        public List<DDAL_SFP_DEV_LOCAL_RADIO_IF> GetDDAL_SFP_DEV_LOCAL_RADIO_IF_modelList(string result)
        {
            List<string> DDAL_SFP_DEV_LOCAL_RADIO_IF_LIST = new List<string>();
            List<DDAL_SFP_DEV_LOCAL_RADIO_IF> DDAL_SFP_DEV_LOCAL_RADIO_IF_modelList = new List<DDAL_SFP_DEV_LOCAL_RADIO_IF>();

            int k = 1;
            while (result.IndexOf("DDAL_SFP_DEV_LOCAL_RADIO_IF_" + k.ToString()) != -1)
            {
                int indexEnd = result.Length;
                int k1 = k + 1;
                if (result.IndexOf("DDAL_SFP_DEV_LOCAL_RADIO_IF_" + (k1).ToString()) != -1)
                    indexEnd = result.IndexOf("DDAL_SFP_DEV_LOCAL_RADIO_IF_" + (k1));
                else
                    indexEnd = result.IndexOf("DDAL_SFP_DEV_LOCAL_SHARED_");

                //DDAL_SFP_DEV_LOCAL_RADIO_IF_ 获取
                DDAL_SFP_DEV_LOCAL_RADIO_IF_LIST.Add(result.Substring(result.IndexOf("DDAL_SFP_DEV_LOCAL_RADIO_IF_" + k.ToString()), indexEnd - result.IndexOf("DDAL_SFP_DEV_LOCAL_RADIO_IF_" + k.ToString())));
                k++;
            }

            for (int i2 = 0; i2 < DDAL_SFP_DEV_LOCAL_RADIO_IF_LIST.Count; i2++)
            {
                DDAL_SFP_DEV_LOCAL_RADIO_IF model = GetDDAL_SFP_DEV_LOCAL_RADIO_IF_model(DDAL_SFP_DEV_LOCAL_RADIO_IF_LIST[i2]);
                DDAL_SFP_DEV_LOCAL_RADIO_IF_modelList.Add(model);
            }
            return DDAL_SFP_DEV_LOCAL_RADIO_IF_modelList;
        }

        private string coherency字符的处理(string _s,string RepString)
        {
            string returnString = "";

            try
            {
                returnString = _s.Trim();
                string returnString2 = returnString.Substring(returnString.IndexOf(RepString),  returnString.IndexOf(","));
               returnString = returnString2.Replace(RepString, "");
                        

                return returnString.Trim();
            }
            catch
            {
                return returnString;
            }


 

        }
    
    }
}
